﻿using System.Collections.Generic;
using System.Linq;
using Couchbase;
using Enyim.Caching.Memcached;
using Sportsbook.CouchbasePersistence.CouchbaseClients;
using Sportsbook.CouchbasePersistence.Models.Bets;
using Sportsbook.Domain.Models.Bets;
using Sportsbook.Domain.Repositories;

namespace Sportsbook.CouchbasePersistence.Repositories
{
    public class BetsRepository: IBetsRepository
    {
        private readonly BetsClient client;

        public BetsRepository(BetsClient client)
        {
            this.client = client;
        }

        public List<IBet> Get(string customerId)
        {
            var view = client.GetView<Bet>("bets", "bet-list", true).Stale(StaleMode.False);
            return view.Cast<IBet>().ToList();
        }

        public void Save(IBet model, string customerId)
        {
            var key = "bet/" + customerId;
            client.StoreJson(StoreMode.Set, key, model);
        }
    }
}
